package edu.berkeley.cs160.innovationers.shoppersidekick;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class AddItem extends Activity implements OnClickListener{
	EditText myQTY;
	AutoCompleteTextView myTitle;
    static final String[] ItemNAMES = new String[] {
    	"Apples","Bananas","Berries","Grapes","Lemons","Lime","Melons","Nectarines","Oranges","Peaches","Pears","Plums","Strawberries","Watermelon","Asparagus","Broccoli","Cabbage","Carrots","Cauliflower","Celery","Corn","Garlic","Lettuce","Mushrooms","Onions","Peppers","Potato","Squash","Sweet Potato","Tomatoes","Zucchini",
    	"Cherries","Mixed Fruit","Peaches","Pears","Pineapples","Asparagus","Carrots","Corn","Greenbeans","Peas","Potatoes","Tomatoes","Baked Beans","Butter Beans","Green Beans","Kidney Beans","Pinto Beans","PorkNBeans","String Beans","Broccoli","Carrots","Corn","Dinners","French Fries","Ice Cream","Peas","Pizzats","Ground",
    	"Hamburger","Roast","Steaks","Chicken","Ham","Roast Beef","Smoked Turkey","Turkey","Bacon","Chops","Ham","Roast","Sausage","Crabmeat","Fish","Scallops","Shrimp","Corned Beef","Ham","Salmon","Tuna","Vienna Sausage","Celery Salt","Cinnamon","Garlic Powder","Garlic Salt","Ginger","Nutmeg","Onion Powder","Oregano","Paprika",
    	"Parsley","Pepper","Salt","BBQ Sauce","Honey","Horseradish","Jelly","Ketchup","Mayonnaise","Mustard","Peanut Butter","Salsa","Soy Sauce","Syrup","Blue Cheese","French","Italian","Ranch","Thousand Island","Candy","Cookies","Crackers","Nuts","Popcorn","Potato Chips","Pretzels","Raisins","Chicken and Rice","Chicken Noodle",
    	"Cream of Broccoli","Cream of Celery","Cream of Chicken","Cream of Mushroom","Tomato","Vegetable","Vegetable Beef","Vegetable Chicken","Biscuits","Buns","Hamburger","Hot Dog","French","Italian","Rolls","Wheat","White","Coffee","Juice","Milk","Orange Juice","Soft Drinks","Sports Drinks","Tea","Water","Butter","Cheese",
    	"Cottage Cheese","Cream Cheese","Creamer","Eggs","Margarine","Milk","Sliced Cheese","Sour Cream","Yogurt","Green Chili","Refried Beans","Salsa","Spanish Rice","Tacos","Tortillias - Corn","Tortillias - Flour","Baking Powder","Baking Soda","Brown Sugar","Brownie Mix","Cake Mix","Cereal","Cocoa","Cornstarch","Flour","Jello",
    	"Oatmeal","Pancake Mix","Rice","Sugar","Vanilla Extract"
    };
    
	public void onClick(View view) {
		switch(view.getId()) {
		case (R.id.CancelButton):
			setResult(1,null);
			finish();
			break;
		case (R.id.OKButton):
			Intent resultIntent=new Intent();
			resultIntent.putExtra("CONTENT", myTitle.getText().toString());
			if(myQTY.getText().length() > 0){
				resultIntent.putExtra("QTY", Integer.parseInt(myQTY.getText().toString()));
			}else
				resultIntent.putExtra("QTY", 1);
			setResult(myApp.addItem,resultIntent);
			finish();
			break;
		}
	}
	
	
    public void onCreate(Bundle savedInstanceState) {
        
    	super.onCreate(savedInstanceState);
        
        setContentView(R.layout.additem);  
        getWindow().setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        myTitle=(AutoCompleteTextView)findViewById(R.id.ItemName);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.list_item_for_autocomplete,ItemNAMES);
        myTitle.setAdapter(adapter);
        myQTY=(EditText)findViewById(R.id.ItemQty);
        Button myCancelButton=(Button)findViewById(R.id.CancelButton);
        Button myOKButton=(Button)findViewById(R.id.OKButton);
        
        //populate spinner with 1-20 items here
        //ArrayAdapter<CharSequence> SpinnerAdapter;
        //SpinnerAdapter=new ArrayAdapter(this,android.R.layout.simple_spinner_item);
        //SpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        //mySpinner=(Spinner)findViewById(R.id.ItemQty);
        //mySpinner.setAdapter(SpinnerAdapter);
        //for (int i=1;i<=20;i++) {
        //	SpinnerAdapter.add(String.valueOf(i));
        //}
        //mySpinner.setSelection(0);
        //population done
        
        
        myCancelButton.setOnClickListener(this);
        myOKButton.setOnClickListener(this);

    }
}
